import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

import departmentsRoute from './modules/departments'
import employeesRoute from './modules/employees'
import settingsRoute from './modules/settings'
import salarysRoute from './modules/salarys'
import socialRoute from './modules/social_securitys'
import attendancesRoute from './modules/attendances'
import approvalsRoute from './modules/approvals'
import permissionsRoute from './modules/permissions'

// 动态路由表，项目中不同的用户可以访问不同的功/
export const asyncRoutes = [
  departmentsRoute,
  settingsRoute,
  employeesRoute,
  permissionsRoute,
  salarysRoute,
  socialRoute,
  attendancesRoute,
  approvalsRoute
]

// 静态路由表
export const constantRoutes = [
  {
    path: '/import',
    component: Layout,
    hidden: true, // 不显示到左侧菜单
    children: [{
      path: '',
      component: () => import('@/views/import')
    }]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  }
]

const createRouter = () => new Router({
  // 控制路由滚动行为  滚动到顶部
  scrollBehavior: () => ({ y: 0 }),
  // 组合到一起组成路由表
  routes: [...constantRoutes]
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
